package com.zyd.blog.homeart.util;

import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
@Component
public class TimeUtil {
    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private final SimpleDateFormat sdfnmy = new SimpleDateFormat("yyyy-MM-dd");
    public int minute(String date) throws ParseException {
        long time = sdf.parse(date).getTime();
        long l = System.currentTimeMillis();
        return (int)(l-time) / (1000 * 60);
    }

    public int day(String date) throws ParseException {
        long time = sdfnmy.parse(date).getTime();
        long l = System.currentTimeMillis();
        return (int)(time-l) / (1000 * 60 * 60 * 24);
    }

//    public static void main(String[] args)throws ParseException  {
//        TimeUtil timeUtil = new TimeUtil();
//        SimpleDateFormat sdfnmy = new SimpleDateFormat("HH:mm:ss");
//       // String format = sdfnmy.format(sdfnmy.parse("2020-02-11 19:03:41"));
//        //int day = timeUtil.day("2020-02-11 19:03:41");
//        System.out.println("2020-02-11 19:03:41".substring(11,16));
//
//    }
}
